<template>
  <div class="html">
    <div class="header">
      <div>
        <i class="svg-icon icon-back" @click="back"></i>
        <h2>我的快递地址</h2>
      </div>
    </div>
    <div class="main">
      <div class="address" v-for="(item, index) in addressList" :key="index">
        <div class="name">
          <span>{{ item.username }}</span>
          <span>{{ item.phone }}</span>
        </div>
        <div class="citys">
          <p>{{ item.detail }}</p>
        </div>
        <div class="operate">
          <div class="left">
            <i></i>
            <span>默认地址</span>
          </div>
          <div class="right">
            <a href="javascript:void(0);" @click="handleUpdate(index)" class="upd">
              <i class="svg-icon icon-edit"></i>
              修改
            </a>
            <a href="" class="del" @click.prevent="handleDel(index)">
              <i class="tw"></i>
              删除
            </a>
          </div>
        </div>
      </div>
      <div class="add" @click="handleUpdate(-1)">
        <button>新增快递地址</button>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  methods: {
    back(){
      history.back()
    },
    handleDel(idx) {
      this.$store.commit("address/addressDelMut", idx);
    },
    handleUpdate(index) {
      if (index == -1) {
        this.$router.push({
          path: "/add",
          query: { idx: -1 },
        });
      } else {
        this.$router.push({
          path: "/add",
          query: {
            idx: index,
          },
        });
      }
    },
  },
  computed: {
    // ...mapState({
    //   addressList: (state) => state.address.addressList, //address.js文件里面的addressList数据包
    // }),
    addressList() {
      return this.$store.state.address.addressList;
    }
  },
  created() {
    console.log(this.addressList);
  },
};
</script>

<style lang="scss" scoped>
.header {
  position: flex;
  top: 0;
  left: 0;
  width: 100%;
  height: 34px;
  color: #000;
  box-sizing: border-box;
  z-index: 99;
  border-bottom: 1px solid #ccc;
  background: #fff;
  text-align: center;
  line-height: 34px;

  h2 {
    font-size: 16px;
    font-weight: 700;
  }
  .svg-icon {
    display: inline-block;
    width: 25px;
    height: 25px;
    background-size: cover;
    background-position: 50%;
    background-repeat: no-repeat;
  }

  .icon-back {
    position: absolute;
    top: 5px;
    left: 10px;
    background-image: url();
  }
}

.address {
  width: 100%;
  height: 118px;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  background: #fff;
  margin-top: 2px;
  .name {
    width: 95%;
    height: 23px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    span {
      font-size: 14px;
      color: #666d71;
      // font-weight: 550;
    }
  }
  .citys {
    width: 95%;
    p {
      font-size: 14px;
      color: #666d71;
    }
  }
  .operate {
    width: 95%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .left {
      // width: 25px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      color: #1296db;
      i {
        width: 25px;
        height: 25px;
        background-size: cover;
        vertical-align: text-bottom;
        background: url()
          no-repeat;
      }
      span {
        padding-left: 4px;
        font-size: 15px;
      }
    }
    .right {
      width: 100px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      color: #1296db;
      a {
        display: inline-block;
        font-size: 16px;
        color: #666d71;
      }
    }
  }
}
.upd,
.del {
  display: inline-block;
  width: 100px;
  text-align: center;
}
.svg-icon {
  width: 25px;
  height: 25px;
  background-size: cover;
  background-position: 50%;
  background-repeat: no-repeat;
  .icon-edit {
    background-repeat: no-repeat;
    background-image: url();
  }
  // background-size: cover;
  // background-position: 50%;
}
.add {
  background: #fff;
  margin-top: 10px;
  button {
    background-color: #179de1;
    border: 1px solid #179de1;
    width: 96%;
    margin: 0.5rem 2%;
    height: 32px;
    color: #fff;
    font-size: 16px;
  }
}
</style>